/**
 * 青蛙
 */
import BaseRole from "battle/components/role/BaseRole";
import Map from "battle/components/Map";
import { StaticBullet } from "battle/components/role/Bullet";
import { createSkeleton } from "utils/util";
import { Direct, Catapult } from "../Weapon";
import FrogBullet from "./FrogBulle";


const { Event } = Laya;

 export default class Frog extends BaseRole {

    constructor(data) {
        super(data);
        this.ho = 3;
        this.initBody();
        this.weapon = new Direct(FrogBullet);
    }

    initBody() {
    	let leftHandle = this.leftHandle = createSkeleton("assets/role/3/game/skin_1_lhand");
        let rightHandle = this.rightHandle = createSkeleton("assets/role/3/game/skin_1_rhand");
        leftHandle.scale(0.5, 0.5);
        rightHandle.scale(0.5, 0.5);
        leftHandle.play("static", true);
        rightHandle.play("static", true);
        leftHandle.pos(5, -40);
        rightHandle.pos(0, -30);
        leftHandle.zOrder = 2;
        this.addChild(leftHandle);
        this.addChildAt(rightHandle, 0);
    }

    set faceDirect(val) {
        this._faceDirect = val;
        let t = 0.5 * val;
        this.body.scaleX = this.leftHandle.scaleX = this.rightHandle.scaleX = t;
    }

    set walkStatus(val) {
        if (this._walkStatus === val) return;
        this._walkStatus = val;
        switch(val) {
            case 0:
            	this.leftHandle.play("static", true);
        		this.rightHandle.play("static", true);
                this.body.play("standby", true);
                break;
            case 1:
                this.body.play("walk", true);
                this.leftHandle.play("walk", true);
        		this.rightHandle.play("walk", true);
                break;
        }
    }


    /**
     * 攻击指示器
     */
    updateSightLine(direct) {
        let graphics = this.indicator.graphics;
        graphics.clear();
        graphics.drawCircle(300*direct[0], 300*direct[1], 100, "#ffffff");
        this.indicator.alpha = 0.5;
        this.indicator.scaleY = 0.25;
        (direct[0]!==0) && (this.faceDirect = (direct[0]<0)? -1: 1);
    }


    attack(data) {
        this.weapon.fire(this.x, this.y-50, 800, 800);
        this.walkStatus = 3;
    }

 }